package ltutils

import (
	"fmt"
	"math/rand"
	"strconv"
	"strings"
	"time"
)

func getRand() *rand.Rand {
	return rand.New(rand.NewSource(time.Now().UnixNano()))
}

// CreateRandNum10 生成10位随机数
func CreateRandNum10() string {
	return fmt.Sprintf("%08v", rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(10000000000))
}

// RandNum 生成两个数值之间的随机数,min,max都应该大于0
func RandNum(min, max int) int {
	if min >= max || max == 0 {
		return max
	}
	n := getRand().Intn(max - min)
	return n + min
}

func RandString(length int) string {
	r := getRand()
	rs := make([]string, length)
	for start := 0; start < length; start++ {
		t := r.Intn(3)
		if t == 0 {
			rs = append(rs, strconv.Itoa(r.Intn(10)))
		} else if t == 1 {
			rs = append(rs, string(rune(r.Intn(26)+65)))
		} else {
			rs = append(rs, string(rune(r.Intn(26)+97)))
		}
	}
	return strings.Join(rs, "")
}
